<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class AppController extends Controller {

    var $name = "App";
    public $components = array(
        'Session',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
            )
        ),
        'RequestHandler',
        'Acl'
    );
    var $helpers = array('Html', 'Form', 'Javascript', "Ajax", 'Session', 'Js');

    function beforeFilter() {
        //Disable error reporting
        //COMENTAR Y DESCOMENTAR ESTA LIENA ES LA QUE MUESTRA ERRORES O NO EN CAKE
         error_reporting(0);
//Report runtime errors
        $this->Auth->allow(array('login','send','logout'));
        //$this->Auth->allow(array('*'));
        $this->disableCache();
        if (!$this->RequestHandler->isAjax()) {
            //Se realiza cuando la petición no es ajax. Cuando carga toda la página.

            App::import("Model", "Tab");
            $tab = new Tab();
            $tab->recursive = -1;

            $grupo = $this->Auth->user('group_id');

            $options['conditions'] = array('GroupsTab.group_id' => $grupo);
            $options['joins'] =
                    array(
                        array('table' => 'groups_tabs',
                            'alias' => 'GroupsTab',
                            'type' => 'LEFT',
                            'conditions' => array(
                                'Tab.id = GroupsTab.tab_id',
                            )
                        )
            );
            $options['order'] = array('Tab.id ASC');
            $lista = $tab->find('all', $options);

            $this->set('lista', $lista);

            $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
            //$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'home');
            $this->Auth->authError = 'Está tratando de entrar a una zona  restringida';
            $this->Session->write('Auth.redirect', null);
        }
        if (sizeof($this->uses) && $this->{$this->modelClass}->Behaviors->attached('Logable')) {
            $this->{$this->modelClass}->setUserData($this->Session->read('Auth'));
        }
    }

}

?>
